package utils

type BufferInterface interface {
	Append(data []byte)
	Popfront(cnt int)
	Get(index int) (byte, error)
	IndexIs(index int, value byte) bool
	Len() int
	Clear()
}

type Buffer struct {
	data []byte
}

func NewBuffer() *Buffer {
	return &Buffer{
		data: make([]byte, 0, 500),
	}
}

func (b *Buffer) Append(data []byte) {
	b.data = append(b.data, data...)
}

func (b *Buffer) Popfront(cnt int) {
	if cnt >= len(b.data) {
		b.data = make([]byte, 0)
	} else {
		b.data = b.data[cnt:]
	}
}

func (b *Buffer) Get(index int) byte {
	if index >= len(b.data) {
		return 0x00
	}
	return b.data[index]
}
func (b *Buffer) IndexIs(index int, value byte) bool {
	if index >= len(b.data) {
		return false
	}
	return b.data[index] == value
}

func (b *Buffer) Len() int {
	return len(b.data)
}
func (b *Buffer) Clear() {
	b.data = make([]byte, 0)
}

func (b *Buffer) GetBytes() []byte {
	return b.data
}
